package hu;

import java.util.*;

public class question_kaogu {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        sc.nextLine();
        String[] str = sc.nextLine().split(" ");
        Arrays.sort(str);
        List<List<String>> ans = new ArrayList<>();
        int[] used = new int[str.length];
        List<String> path = new ArrayList<>();
        trackBack2(ans, path, str, used);
        System.out.println(ans);

    }
    public static void trackBack1(List<List<String>> ans, List<String> path, String[] str, int[] used){
        if(path.size() == str.length){
            ans.add(new ArrayList<>(path));
            return;
        }
        Set<String> flag = new HashSet<>();
        for (int i = 0; i < str.length; i++) {

            if(used[i] == 1)
                continue;
            if(flag.contains(str[i]))
                continue;
            used[i] = 1;
            path.add(str[i]);
            flag.add(str[i]);
            trackBack1(ans, path, str, used);
            used[i] = 0;
            path.remove(path.size() - 1);

        }
    }

    public static void trackBack2(List<List<String>> ans, List<String> path, String[] str, int[] used){
        if(path.size() == str.length){
            ans.add(new ArrayList<>(path));
            return;
        }
        for (int i = 0; i < str.length; i++) {

            if(used[i] == 1)
                continue;
            /*
            i - 1 == 0 证明在本层已经使用过了,则跳过
             */
            if(i != 0 && used[i - 1] == 0 && str[i].equals(str[i - 1]))
                continue;
            used[i] = 1;
            path.add(str[i]);
            trackBack2(ans, path, str, used);
            used[i] = 0;
            path.remove(path.size() - 1);

        }
    }
}
